﻿using System;
using System.Data;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using log4net;

namespace Dune.Web.AppCode
{
    public class BaseGlobal : HttpApplication
    {
        #region Constants

        private const string NOT_AVALIABLE_PAGE = "NotAvailable.aspx";

        #endregion

        #region Fields

        private static bool initialized = true;

        private static string startupException = null;

        private readonly static ILog log = LogManager.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType);

        #endregion

        #region Constructor

        public BaseGlobal()
        {
        }

        #endregion

        #region Properties

        public bool Initialized
        {
            get { return initialized; }
        }

        public string StartupException
        {
            get { return startupException; }
        }

        #endregion


        protected void RegisterError(Exception ex)
        {
            startupException = ex.ToString() +
                "\n" + ex.Message +
                "\n" + ex.Source +
                "\n" + ex.StackTrace;
            initialized = false;
        }

        protected void CheckInitialized()
        {
            if (!Initialized)
            {
                HttpRequest request = HttpContext.Current.Request;
                string naPath = request.ApplicationPath + "/" + NOT_AVALIABLE_PAGE;
                naPath = naPath.Replace("//", "/");
                if (naPath != request.Path)
                    HttpContext.Current.Response.Redirect(NOT_AVALIABLE_PAGE, true);
            }
        }


    }

}
